using System.Data;
using System.Data.SqlClient;
using DataAccessLayer;
using EntityObjectLayer;

namespace BusinessLogicLayer
{
    public class BLTaskAssign
    {
        public int Saved(BETaskAssign beTaskAssign, string Type)
        {
            SqlParameter Class = new SqlParameter("@Class", SqlDbType.Char, 10);
            Class.Value = beTaskAssign.sClass;
            SqlParameter Teacher = new SqlParameter("@Teacher", SqlDbType.Char, 10);
            Teacher.Value = beTaskAssign.sTeacher;
            SqlParameter Subject = new SqlParameter("@Subject", SqlDbType.Char, 5);
            Subject.Value = beTaskAssign.sSubject;
            SqlParameter TimeSlot = new SqlParameter("@TimeSlot", SqlDbType.NVarChar, 50);
            TimeSlot.Value = beTaskAssign.sTimeSlot;

            int returnInt = 0;
            switch (Type)
            {
                case "Insert":
                    returnInt = Common.Execute("pr_tblTaskAssign_Insert", Class, Teacher, Subject, TimeSlot);
                    break;
                case "Update":
                    returnInt = Common.Execute("pr_tblTaskAssign_Update", Class, Teacher, Subject, TimeSlot);
                    break;
            }
            return returnInt;
        }

        public int Delete(BETaskAssign beTaskAssign)
        {
            SqlParameter Class = new SqlParameter("@Class", SqlDbType.Char, 10);
            Class.Value = beTaskAssign.sClass;
            SqlParameter Teacher = new SqlParameter("@Teacher", SqlDbType.Char, 10);
            Teacher.Value = beTaskAssign.sTeacher;
            SqlParameter Subject = new SqlParameter("@Subject", SqlDbType.Char, 5);
            Subject.Value = beTaskAssign.sSubject;

            return Common.Execute("pr_tblTaskAssign_Delete", Class, Teacher, Subject);
        }

        public DataTable SelectAll()
        {
            return Common.GetFromDataTable("pr_tblTaskAssign_SelectAll");
        }

        public DataTable SelectAllSubject()
        {
            return Common.GetFromDataTable("pr_tblSubject_SelectAll");
        }

        public DataTable SelectAllClassasClassName()
        {
            return Common.GetFromDataTable("pr_tblClass_SelectAllAsClassName");
        }

        public DataTable SelectObjectByClassID(BETaskAssign beTaskAssign)
        {
            SqlParameter Class = new SqlParameter("@ClassID", SqlDbType.Char, 10);
            Class.Value = beTaskAssign.sClass;
            return Common.GetFromDataTable("pro_tblTaskAssign_SelectSubjectByClassID", Class);
        }

        public DataTable SelectTeacherBySubjectID(BETaskAssign beTaskAssign, string Type)
        {
            SqlParameter SubjectID = new SqlParameter("@SubjectID", SqlDbType.Char, 10);
            SubjectID.Value = beTaskAssign.sSubject;
            SqlParameter Types = new SqlParameter("@Type", SqlDbType.Char, 10);
            Types.Value = Type;
            return Common.GetFromDataTable("pro_tblTaskAssign_SelectTeacherBySubjectID", SubjectID, Types);
        }
    }
}